package com.hyyt.shopjsp.customer.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.hyyt.shopjsp.util.common.Utils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hyyt.shopjsp.basic.pojo.BasicUsers;
import com.hyyt.shopjsp.basic.service.IBasicActorPurviewService;
import com.hyyt.shopjsp.common.controller.BaseController;
import com.hyyt.shopjsp.customer.service.IShopCustomerCollectProductService;
import com.hyyt.shopjsp.customer.service.IShopCustomerCollectShopService;
import com.hyyt.shopjsp.util.common.Page;
import com.hyyt.shopjsp.util.common.ResultMsg;

/**
 * Copyright (c) 2017 ShopJsp. All Rights Reserved.
 * ============================================================================
 * 版权所有 2011 - 今 北京华宇盈通科技有限公司，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 提示：在未取得SHOPJSP商业授权之前，您不能将本软件应用于商业用途，否则SHOPJSP将保留追究的权力。
 * ----------------------------------------------------------------------------
 * 官方网站：http://www.shopjsp.com
 * ============================================================================
 * @author Wang Youchun on 2017/4/5 0024下午 13:21.
 */
@Controller
@RequestMapping("/back/customerCollectProduct")
public class ShopCustomerCollectController extends BaseController {
	private Logger log = Logger.getLogger(ShopCustomerCollectController.class);
	private String basePath = "/back/shop/customerCollectProduct/";

	@Resource
	private IShopCustomerCollectProductService shopCustomerCollectProductService;//用户收藏商品service
	@Resource
	private IShopCustomerCollectShopService shopCustomerCollectShopService;//用户收藏店铺service
	/**
	 * 进入会员商品收藏管理
	 * @param customerId
	 * @param param
	 * @return
	 */
	@RequestMapping("findCustomerCollectProductListByCustomerId")
	public String findCustomerCollectProductListByCustomerId(String customerId,Map<String, Object> param){
        param.put("customerId", customerId);
		return basePath+"customerCollectProductList";
	}

	/**
	 * 进入会员店铺收藏管理
	 * @param customerId
	 * @param param
	 * @return
	 */
	@RequestMapping("findCustomerCollectShopInfoListByCustomerId")
	public String findCustomerCollectShopInfoListByCustomerId(String customerId,Map<String, Object> param){
		param.put("customerId", customerId);
		return basePath+"customerCollectShopInfoList";
	}

	/**
	 * 查询所有会员商品收藏
	 * @param customerId
	 * @param productName
	 * @param shopName
	 * @param page
	 * @param response
	 */
	@RequestMapping(value="listCustomerCollectProduct",method=RequestMethod.POST)
	@ResponseBody
	public void listCustomerCollectProduct(Integer customerId,String productName,String shopName,Page page, HttpServletResponse response){
		Map<String, Object> param=new HashMap<>();
		if(Utils.objectIsNotEmpty(productName)){//是否检索商品名称
			param.put("productName", productName.trim());
		}
		if(Utils.objectIsNotEmpty(shopName)){//是否检索店铺名称
			param.put("shopName", shopName.trim());
		}
		param.put("customerId", customerId);
		param.put("sortColumns", "customerCollectProductId desc");
		int totalRecordCount =shopCustomerCollectProductService.countShopCustomerCollectProduct(param);
		page.setPageInfo(page.getPageSize(), totalRecordCount, page.getCurrentPage());
		List<Map<String,Object>> customerCollectProductList =shopCustomerCollectProductService.queryShopCustomerCollectProductByCustomerId(param, page.getPageRecordBeginIndex(), page.getPageSize());
		param.clear();
		param.put("total", totalRecordCount);// total键 存放总记录数，必须的
		param.put("rows", customerCollectProductList);// rows键 存放每页记录 list
		ResultMsg.create(param, response);  //把内容发送到页面
	}

	/**
	 * 查询所有会员店铺收藏
	 * @param customerId
	 * @param shopName
	 * @param page
	 * @param response
	 */
	@RequestMapping(value="listCustomerCollectShopInfo",method=RequestMethod.POST)
	@ResponseBody
	public void listCustomerCollectShopInfo(Integer customerId,String shopName,Page page, HttpServletResponse response){
		Map<String, Object> param=new HashMap<>();
		if(Utils.objectIsNotEmpty(shopName)){//是否检索店铺名称
			param.put("shopName", shopName.trim());
		}
		param.put("customerId", customerId);
		param.put("sortColumns", "customerCollectShopId desc");
		int totalRecordCount =shopCustomerCollectShopService.countShopCustomerCollectShop(param);
		page.setPageInfo(page.getPageSize(), totalRecordCount, page.getCurrentPage());
		List<Map<String, Object>> customerCollectProductList =shopCustomerCollectShopService.queryShopCustomerCollectShopByCustomerId(param, page.getPageRecordBeginIndex(), page.getPageSize());
		param.clear();
		param.put("total", totalRecordCount);// total键 存放总记录数，必须的
		param.put("rows", customerCollectProductList);// rows键 存放每页记录 list
		ResultMsg.create(param, response);  //把内容发送到页面
	}
}